package org.neuedu.his.service.sys;

import org.neuedu.his.mapper.RuleMapper;
import org.neuedu.his.model.RespBean;
import org.neuedu.his.model.Rule;
import org.neuedu.his.model.RuleDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RuleService {
    @Autowired
    RuleMapper ruleMapper;
    public RespBean addRule(RuleDataUtils ruleDataUtils) {
        if (ruleDataUtils.getRuleName()==null||ruleDataUtils.getRuleName().trim().equals("")){
            return RespBean.error(500,"请输入规则名字");
        }else {
            String rulename=ruleDataUtils.getRuleName();
            int[] deptIds=ruleDataUtils.getDeptIds();
            int[] userIds = ruleDataUtils.getUserIds();
            String[] week =ruleDataUtils.getWeek();
            for (int i= 0;i<week.length;i++){
                int deptId =deptIds[i];
                int userId =userIds[i];
                String weekOne =week[i];
                Rule rule =new Rule();
                rule.setDeptid(deptId);
                rule.setUserid(userId);
                rule.setWeek(weekOne);
                rule.setRulename(rulename);
                ruleMapper.insertSelective(rule);
            }
        return RespBean.success(200,"添加成功");
        }
    }

    public List<Rule> getHadRules(int deptId) {
        return ruleMapper.getHadRules(deptId);

    }
}
